//
//  LoginViewController.m
//  XDCommonApp
//
//  Created by XD-XY on 2/13/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "LoginViewController.h"
#import "XDTabBarViewController.h"
#import "UserInfo.h"
#import "XRRegistViewController.h"
#import "XRImmeLoginViewController.h"
#import "XRForgetViewController.h"


@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.titleLabel.text = @"登录";
}
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    UIImageView *logoImageView=[[UIImageView alloc]initWithFrame:CGRectMake(UI_SCREEN_WIDTH/2.0 +20, UI_TAB_BAR_HEIGHT +UI_STATUS_BAR_HEIGHT +30, 60, 60)];
    logoImageView.backgroundColor=[UIColor greenColor];
    [self.view addSubview:logoImageView];
    
//    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, VIEW_POINT_MAX_Y(logoImageView), 30, 30)];
//    imageView.backgroundColor=[UIColor redColor];
//    [self.view addSubview:imageView];
//    userNameField =creatXRTextField(@"请输入用户名", CGRectMake(VIEW_POINT_MAX_X(imageView),VIEW_POINT_MAX_Y(logoImageView),150,30));
//    userNameField.delegate=self;
//    [self.view addSubview:userNameField];
//
//    UIImageView *passImageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, VIEW_POINT_MAX_Y(userNameField), 30, 30)];
//    [passImageView setBackgroundColor:[UIColor redColor]];
//    [self.view addSubview:passImageView];
//    passWordField =creatXRTextField(@"请输入密码", CGRectMake(VIEW_POINT_MAX_X(passImageView), VIEW_POINT_MAX_Y(userNameField), 150, 30));
//    [self.view addSubview:passWordField];
    
    UIButton *bnt=creatXRButton(CGRectMake(UI_SCREEN_WIDTH/2.0 +10, UI_SCREEN_HEIGHT - 200, 80, 40),@"立即登录",nil,nil);
    [bnt addTarget:self action:@selector(loginButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:bnt];
    
    UIButton *registButton=creatXRButton(CGRectMake(80, UI_SCREEN_HEIGHT -100, UI_SCREEN_WIDTH/2.0 - 50, 40),@"注册账号",nil,nil);
    [registButton addTarget:self action:@selector(registButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registButton];
    UIButton *forgetWordButton=creatXRButton(CGRectMake(UI_SCREEN_WIDTH/2.0 +40, UI_SCREEN_HEIGHT -100, UI_SCREEN_WIDTH/2.0 - 50, 40), @"忘记密码", nil, nil);
    [forgetWordButton addTarget:self action:@selector(forgetButtonClck:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:forgetWordButton];
}
-(void)loginButtonClick:(UIButton *)sender{

    XRImmeLoginViewController *immeLoginVC=[[XRImmeLoginViewController alloc]init];
    [self presentViewController:immeLoginVC animated:YES completion:^{
        
    }];
    //    [self.navigationController immeLoginVC animated:YES];
}
-(void)registButtonClick:(UIButton *)sender{
    XRRegistViewController *registVC=[[XRRegistViewController alloc]init];
    [self presentViewController:registVC animated:YES completion:^{
        
    }];
//    [self.navigationController pushViewController:registVC animated:YES];
    
}
-(void)forgetButtonClck:(UIButton *)sender{
    XRForgetViewController *forgetVC=[[XRForgetViewController alloc]init];
    [self presentViewController:forgetVC animated:YES completion:^{
        
    }];
    //    [self.navigationController immeLoginVC animated:YES];
}
#pragma mark textField delegate

- (BOOL)textFieldShouldClear:(UITextField *)textField{
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self hideTheKeyboard];
    return YES;
}
-(void)hideTheKeyboard{
    [userNameField resignFirstResponder];
    [passWordField resignFirstResponder];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    [self hideTheKeyboard];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
